package c;

import java.util.HashSet;
import java.util.Objects;
import java.util.Scanner;

//p203 任务实施
class Student{
    private String name;
    private int age;
    private String phone;
    public Student(){
        super();
    }
    public Student(String name,int age,String phone){
        super();
        this.name = name;
        this.age = age;
        this.phone = phone;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return  name + "\t" + age + "\t" + phone ;
    }

    @Override
    public int hashCode(){
        int hc = 1;
        hc = 31 * hc + ((name == null) ? 0 : hashCode());
        hc = 31 * hc + age;
        hc = 31 * hc + ((phone == null) ? 0 : hashCode());
        return hc;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null)
            return false;
        if (getClass() != o.getClass())
            return false;
        Student student = (Student) o;
        if (name == null) {
            if (student.name != null) {
                return false;
            }
        }else if (! name.equals(student.name))
            return false;
        if (age != student.age)
            return false;
        if (phone == null){
            if (student.phone != null)
                return false;
        }
        else if (! phone.equals(student.phone))
            return false;
        return true;
    }
}
public class demo4 {
    public static void main(String[] args) {
        HashSet<Student> hs = new HashSet<Student>();
        while (true){
            Scanner sc = new Scanner(System.in);
            System.out.print("是否要输入学生信息（Y:是，N:否）");
            if (sc.next().equalsIgnoreCase("y")) {
                System.out.print("请输入学生的姓名:");
                String name = sc.next();
                System.out.print("请输入学生的年龄:");
                int age = sc.nextInt();
                System.out.print("请输入学生的手机号:");
                String phone = sc.next();
                Student stu = new Student(name,age,phone);
                hs.add(stu);
            }else
                break;
        }
        System.out.println("***************************************");
        System.out.println("XXXXXXXXXXXX班学生信息表 ");
        System.out.println("姓名\t年龄\t电话");
        System.out.println("---------------------------------------");
        for(Student stu : hs){
            System.out.println(stu);
        }
    }
}
